package com.back.util;

import java.util.regex.Pattern;

public class RegexPhoneUtil {

    private static final Pattern chMob = Pattern.compile("^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[3,5,6,7,8])|(18[0-9])|(19[8,9]))\\d{8}$");
    private static final Pattern hxMob = Pattern.compile("^([5689])\\d{7}$");

    private static final Pattern chPhone = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$");//带区号
    private static final Pattern hxPhone = Pattern.compile("^[1-9][0-9]{5,8}$");//不带区号

    /**
     * 校验手机号格式是否正确
     * @param phone
     * @return
     */
    public static Boolean regexPhone(String phone){
        if(phone.length() < 4){
            return false;
        }else{
           return chMob.matcher(phone).matches()
                   || hxMob.matcher(phone).matches()
                   || chPhone.matcher(phone).matches()
                   || hxPhone.matcher(phone).matches();
        }
    }
}
